﻿using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Rendering;
using System;
using System.Collections.Generic;
using System.Resources;
using System.Windows;
using TextMateSharp.Grammars;

namespace JsonCodeGenerator
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private readonly MainViewModel _mainViewModel = new();
        private int _currentTheme = (int)ThemeName.DarkPlus;
        private RegistryOptions _registryOptions;
        private TextMate.Installation _textMateInstallation;


        public MainWindow()
        {
            InitializeComponent();
            DataContext = _mainViewModel;
            //this.Initialized += this.MainWindowInitialized; // (TextMate自定义着色方案未实现)
        }
        
        private void MainWindowInitialized(object? sender, EventArgs e)
        {
            JsonEditInit();
        }

        private void JsonEditInit()
        {
            _registryOptions = new RegistryOptions((ThemeName)_currentTheme);
            _textMateInstallation = jsonEditor.InstallTextMate(_registryOptions);

            var language = _registryOptions.GetLanguageByExtension(".json");
            _textMateInstallation.SetGrammar(_registryOptions.GetScopeByLanguageId(language.Id));
        }
    }
}
